package 剑指Offer.easy;

public class 二叉树的镜像 {

    public class TreeNode {
        int val;
        TreeNode left;
        TreeNode right;

        TreeNode(int x) {
            val = x;
        }
    }

    class Solution {
        public TreeNode mirrorTree(TreeNode root) {
            reverse(root);
            return root;
        }

        private void reverse(TreeNode root) {
            if (root == null) {
                return;
            }
            TreeNode tmp = root.left;
            root.left = root.right;
            root.right = tmp;
            reverse(root.left);
            reverse(root.right);
        }
    }
}
